package com.hdu.controller.authorityManagement;

import com.hdu.entity.Menu;
import com.hdu.pojo.Result;
import com.hdu.service.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 菜单实体类 前端控制器
 * </p>
 *
 * @author xiaobai
 * @since 2023-10-28
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "菜单管理接口")
@RequestMapping("/menu")
public class MenuController {

    private final IMenuService menuService;

    @GetMapping
    @ApiOperation("获取菜单列表")
    public Result<?> getAllUserInfo() {
        List<Menu> menuList = menuService.getAllUserInfo("");
        log.info("查询菜单信息：{}", menuList);
        return Result.success(menuList);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除菜单")
    public Result<?> delete(@PathVariable String id) {
        log.info("删除菜单, id:{}", id);
        menuService.removeById(id);
        return Result.success();
    }

    @PostMapping
    @ApiOperation("新增菜单")
    public Result<?> append(@RequestBody Menu menu) {
        log.info("新增菜单, menu: {}", menu);
        menuService.append(menu);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("更新菜单信息")
    public Result<?> update(@RequestBody Menu menu) {
        log.info("更新菜单信息 : {}", menu);
        menuService.updateById(menu);
        return Result.success();
    }
}
